package com.zpark.resume.controller;

import com.zpark.resume.common.ResponseResult;
import com.zpark.resume.common.StatusCode;
import com.zpark.resume.entity.Honor;
import com.zpark.resume.entity.Project;
import com.zpark.resume.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: com.zpark.resume.controller
 * @ClassName: ProjectController
 * @Description:
 * @author: RZS
 * @date: 2023/6/1  22:04
 */
@RestController
@RequestMapping("/project")
@CrossOrigin
public class ProjectController {

    @Autowired
    private IProjectService projectService;

    /**
     * 根据cv_id查询Project数据
     * @param id cv_id
     * @return
     */
    @PostMapping("/find_by_cv_id/{id}")
    public ResponseResult<List<Project>> findRecommendByCvId(@PathVariable("id") Integer id){
        // 调用业务层接口查询数据
        List<Project> projects = projectService.findByCvId(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), projects);
    }

    /**
     * 添加项目经历
     * @param project
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Void> addPro(@RequestBody Project project){
        // 调用业务层接口实现添加操作
        projectService.addProject(project);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 添加项目经历
     * @param project
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<Void> changePro(@RequestBody Project project){
        // 调用业务层接口实现修改操作
        projectService.changeProjectById(project);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 添加项目经历
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult<Void> removePro(@PathVariable("id") Integer id){
        // 调用业务层接口实现删除操作
        projectService.removeProjectById(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }
}
